package com.library.management.controller;

import com.library.management.entity.Book;
import com.library.management.entity.BookCategory;
import com.library.management.service.BookCategoryService;
import com.library.management.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

/**
 * 首页控制器
 */
@Controller
public class IndexController {
    @Autowired
    private BookService bookService;

    @Autowired
    private BookCategoryService bookCategoryService;

    /**
     * 首页
     */
    @GetMapping("/")
    public String index(Model model) {
        // 查询图书分类
        List<BookCategory> categories = bookCategoryService.listAll();
        model.addAttribute("categories", categories);

        // 查询图书列表
        Book book = new Book();
        book.setStatus(1); // 上架状态
        List<Book> books = bookService.list(book, 1, 10).getList();
        model.addAttribute("books", books);

        return "index";
    }

    /**
     * 登录页面
     */
    @GetMapping("/login")
    public String login() {
        return "login";
    }

    /**
     * 注册页面
     */
    @GetMapping("/register")
    public String register() {
        return "register";
    }
}